
import java.net.URL;
import java.security.ProtectionDomain;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class EmbeddedJettyServer {
	public static void main(String[] args) throws Exception {
		int port = Integer.parseInt(System.getProperty("port", "8080"));
		Server server = new Server(port);

		WebAppContext context = new WebAppContext();
		ProtectionDomain protectionDomain = EmbeddedJettyServer.class.getProtectionDomain();
		URL location = protectionDomain.getCodeSource().getLocation();

		context.setWar(location.toExternalForm());
		context.setContextPath("/");
		context.setParentLoaderPriority(true);

		server.setHandler(context);
		server.start();
		server.dump(System.err);
		server.join();
	}

}
